/*
 * ServerGUI.java
 *
 * Created on __DATE__, __TIME__
 */

package server;

import java.rmi.RemoteException;

import common.ServerInterface;

/**
 * 
 * Auto generated GUI, that shows a small window with a shutdown button.
 */
public class ServerGUI extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final ServerInterface server;

	/** Creates new form ServerGUI */
	public ServerGUI(final ServerInterface server) {
		this.server = server;
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		this.jLabel1 = new javax.swing.JLabel();
		this.jButton1 = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("Server");
		setBackground(new java.awt.Color(255, 255, 255));
		setForeground(new java.awt.Color(255, 255, 255));
		setMinimumSize(new java.awt.Dimension(240, 140));
		setName("ServerGUI");
		setResizable(false);
		getContentPane().setLayout(
				new org.netbeans.lib.awtextra.AbsoluteLayout());

		this.jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 24));
		this.jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		this.jLabel1.setText("Server is ready!");
		getContentPane()
				.add(this.jLabel1,
						new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0,
								240, 40));

		this.jButton1.setFont(new java.awt.Font("Segoe UI", 1, 14));
		this.jButton1.setText("Shut down server");
		this.jButton1.setBorder(null);
		this.jButton1.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(final java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});
		getContentPane().add(
				this.jButton1,
				new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 60, 160,
						30));

		pack();
	}// </editor-fold>
		// GEN-END:initComponents

	private void jButton1ActionPerformed(final java.awt.event.ActionEvent evt) {
		try {
			this.server.shutdownClients("User shutdown application");
		} catch (final RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(final String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				// new ServerGUI().setVisible(true);
			}
		});
	}

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JLabel jLabel1;
	// End of variables declaration//GEN-END:variables

}